package com.test22_日期时间;

import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * SimpleDateFormat，日期格式化类
 */
public class Demo03_SimpleDateFormat {

    @Test
    public void test1() throws Exception {
        // Date转String
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        String str = sdf.format(date);
        System.out.println(str);
    }

    @Test
    public void test2() throws Exception {
        // String转Date
        String str = "2021-02-16 14:20:36.873";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        Date date = sdf.parse(str);
        System.out.println(date);
    }
}
